/*
 *  $Id: IllusionLord.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *  This file is a part of Ragima CCG.
 *  (C) 2008 Ragima development group.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System.Collections.Generic;

namespace Ragima.Cards001.Water.Creatures {
    public class IllusionLord: CreatureCard {
        public IllusionLord(): base("001_w_c_illusion_lord") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Water;
            Value = 100;
            Damage = 2;
            Health = 6;
            AddManaCost(ElementType.Water, 5);
        }
        public override void SetNaturalAffects(ICollector<Affect> affects) {
            affects.Add(new Affects.Regeneration(1));
            affects.Add(new Affects.OnHit(DoHandOfIllusion, AffectSummaryType.Local));
        }
        public override void SetAbilities(ICollector<AbilityCard> abilities) {
            abilities.Add<Abilities.IllusionHandR>();
            abilities.Add<Abilities.IllusionHandL>();
        }

        private static void DoHandOfIllusion(Creature hitter, AbstractObject target, int damage) {
            if (target is Creature && !target.HasAffect<HandOfIllusion>())
                target.AddAffect<HandOfIllusion>();
        }

        public static bool HasCreaturesWithHandOfIllusion(AbstractObject caster, Card card) {
            return GetCreaturesWithHandOfIllusion(caster.Owner).Count > 0;
        }

        public static List<Creature> GetCreaturesWithHandOfIllusion(Player owner) {
            List<Creature> list = new List<Creature>();
            GetCreaturesWithHandOfIllusion(owner, list);
            GetCreaturesWithHandOfIllusion(owner.Enemy, list);
            return list;
        }
        private static void GetCreaturesWithHandOfIllusion(Player owner, List<Creature> list) {
            foreach (Creature cr in owner.GetCreatures())
                if (cr.HasAffect<HandOfIllusion>())
                    list.Add(cr);
        }

        private class HandOfIllusion: SpellAffect<IllusionLord> {
            public HandOfIllusion(): base(true) {
                DefaultName = true;
                DefaultDescription = true;
            }
        }
    }
}
